# Copyrigth Rodrigo Garcia strysg@riseup.net
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public Licence as published
# by the Free Software Foundation; either version 3 of the Licence,
# or (at your option) any later version.

# Shutter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from automatas import automata_cadenas

# declarando automatas reglas de transcision de automatas
d_mostrar = {
    0 : [("mostrar +",1)],
    1 : [("[a-zA-Z][a-zA-Z0-9_]*",6), ('\"',2)],
    2 : [('\w\"', 4)],
    4 : [(r".",5)],
    6 : [(r".",5)],
}

d_declarar_entero = {
    0 : [("entero +",1)],
    1 : [("[a-zA-Z][a-zA-Z0-9]*",2)],
#    2 : [("= +|( =)| = |=",3)],
    2 : [(" *= *",3)],
    3 : [("[0-9]+"),4],
    4 : [(r".",5)],
}


print("Interprete de lenguaje rpc")
print("--------------------------")
print("Escriba sus instrucciones a continuacion")

while True:
    m1 = automata_cadenas(d_mostrar, [5])
    m2 = automata_cadenas(d_declarar_entero, [5])
   
    entrada = input("--: ")
     
    # evaluando
    m1.FTrans(entrada)
    m2.FTrans(entrada)

    # resultado de la evaluacion
    print("--- eval mostrar ---")
    if m1.aceptado():
        print ("--- recorridos:"+str(m1.estados_recorridos))
        print ("--- aceptado!")
        # traducir
    else:
       print ("--- recorridos:"+str(m2.estados_recorridos))
       print ("--- final:"+ str(m2.estado))

    print ("")
    print("--- eval 'declarar entero'")
    if m2.aceptado():
        print("--- recorridos: "+str(m2.estados_recorridos))
        print("--- aceptado!")
    else:
        # errores
        print("--- recorridos: "+str(m2.estados_recorridos))
        print("--- final:"+str(m2.estado))

    print("------------------")


